 package com.oanda.blackberry.view;
 
 import com.oanda.blackberry.ui.ColoredLabelField;
 import com.oanda.blackberry.ui.OandaMainScreen;
 import com.oanda.blackberry.ui.SpacerField;
 import com.oanda.blackberry.util.AbstractViewPanel;
 import com.oanda.blackberry.util.DefaultController;
 import com.oanda.blackberry.util.PropertyChangeEvent;
 import com.oanda.blackberry.util.log.Logger;
 import net.rim.blackberry.api.browser.Browser;
 import net.rim.blackberry.api.browser.BrowserSession;
 import net.rim.blackberry.api.invoke.Invoke;
 import net.rim.blackberry.api.invoke.MessageArguments;
 import net.rim.blackberry.api.mail.Address;
 import net.rim.blackberry.api.mail.Message;
 import net.rim.device.api.system.Bitmap;
 import net.rim.device.api.ui.Field;
 import net.rim.device.api.ui.Font;
 import net.rim.device.api.ui.Manager;
 import net.rim.device.api.ui.MenuItem;
 import net.rim.device.api.ui.Screen;
 import net.rim.device.api.ui.component.BitmapField;
 import net.rim.device.api.ui.component.Menu;
 import net.rim.device.api.ui.component.SeparatorField;
 import net.rim.device.api.ui.container.HorizontalFieldManager;
 import net.rim.device.api.ui.container.MainScreen;
 import net.rim.device.api.ui.decor.Background;
 import net.rim.device.api.ui.decor.BackgroundFactory;
 
 public class OtpHelpView extends OandaMainScreen
   implements AbstractViewPanel
 {
   DefaultController controller;
   ColoredLabelField helpHeaderTextLabel;
   ColoredLabelField help2FASetupLabel;
   ColoredLabelField helpMoreInfoLabel;
   ColoredLabelField helpNeedToChangeLabel;
   ColoredLabelField helpStillHavingTroubleLabel;
   static final String HEADER_HELP_TEXT = "To comply with goverment requirements and your own security, you must set up Two-Factor Authentication for your account.";
   static final String HELP_2FA_SETUP = "To Set up Two-Factor Authentication click here";
   static final String HELP_MORE_INFO = "For more information on Two-Factor Authentication click here";
   static final String HELP_NEED_TO_CHANGE = "Need to change the phone number configured for your account? click here";
   static final String HELP_STILL_HAVING_TROUBLE = "Still having trouble logging in or haven't received your SMS? Contact Customer Care at assist@oanda.com or call 1-877-OANDA-FX";
   static final String URL_2FA_SETUP = "https://fxtrade.oanda.com/account/otp/setup/start";
   static final String URL_MORE_INFO = "https://fxtrade.oanda.com/account/otp/setup/help";
   static final String URL_NEED_TO_CHANGE = "https://fxtrade.oanda.com/account/otp/reconfigure/start";
   MenuItem back = new MenuItem("Back", 10, 1001)
   {
     public void run() {
       OtpHelpView.this.onClose();
     }
   };
 
   public OtpHelpView(DefaultController controller)
   {
     this.controller = controller;
     init();
   }
 
   public void modelPropertyChange(PropertyChangeEvent evt) {
     if ((evt.getPropertyName() != null) && (evt.getPropertyName().equals("setErrorMessage")))
     {
       if ((evt.getNewValue() != null) && ((evt.getNewValue() instanceof String))) {
         String statusText = (String)evt.getNewValue();
         diplayError(statusText, 3000);
       }
     }
     else if ((evt.getPropertyName() != null) && (evt.getPropertyName().equals("setOtpHelpStatus"))) {
       Logger.log("OtpHelpView setOtpHelpStatus: " + (String)evt.getNewValue());
       if ((evt.getNewValue() != null) && ((evt.getNewValue() instanceof String))) {
         String statusText = (String)evt.getNewValue();
         if ((statusText != null) && (statusText.length() > 0)) {
           setStatusField(statusText);
         }
         else {
           setStatusField("");
           removeStatusField();
         }
       }
     }
     else if ((evt != null) && (evt.getPropertyName().equals("showThrobber"))) {
       showThrobber();
     }
     else if ((evt != null) && (evt.getPropertyName().equals("hideThrobber"))) {
       hideThrobber();
     }
     else if ((evt != null) && (evt.getPropertyName().equals("showOtpHelpView"))) {
       this.controller.pushScreen(this);
     }
     else if ((evt != null) && (evt.getPropertyName().equals("hideOtpHelpView"))) {
       this.controller.popScreen(this);
     }
   }
 
   protected void makeMenu(Menu menu, int instance) {
     menu.add(this.back);
   }
 
   private void init() {
     getTitleManager().deleteAll();
     getMainManager().setBackground(BackgroundFactory.createSolidBackground(4473924));
 
     createFields();
     layoutFields();
   }
 
   private void createFields() {
     this.helpHeaderTextLabel = new ColoredLabelField(16777215, "To comply with goverment requirements and your own security, you must set up Two-Factor Authentication for your account.");
     this.help2FASetupLabel = new ColoredLabelField(16777215, "To Set up Two-Factor Authentication click here", 18014398509481984L)
     {
       protected boolean navigationClick(int status, int time) {
         Browser.getDefaultSession().displayPage("https://fxtrade.oanda.com/account/otp/setup/start");
 
         return true;
       }
     };
     this.helpMoreInfoLabel = new ColoredLabelField(16777215, "For more information on Two-Factor Authentication click here", 18014398509481984L)
     {
       protected boolean navigationClick(int status, int time) {
         Browser.getDefaultSession().displayPage("https://fxtrade.oanda.com/account/otp/setup/help");
         return true;
       }
     };
     this.helpNeedToChangeLabel = new ColoredLabelField(16777215, "Need to change the phone number configured for your account? click here", 18014398509481984L)
     {
       protected boolean navigationClick(int status, int time) {
         Browser.getDefaultSession().displayPage("https://fxtrade.oanda.com/account/otp/reconfigure/start");
         return true;
       }
     };
     this.helpStillHavingTroubleLabel = new ColoredLabelField(16777215, "Still having trouble logging in or haven't received your SMS? Contact Customer Care at assist@oanda.com or call 1-877-OANDA-FX", 18014398509481984L)
     {
       protected boolean navigationClick(int status, int time) {
         try {
           Message m = new Message();
           Address a = new Address("assist@oanda.com", "Assist at OANDA");
           Address[] addresses = { a };
           m.addRecipients(0, addresses);
           m.setContent("");
           m.setSubject("Please assist me with Two-Factor Authentication");
 
           Invoke.invokeApplication(2, new MessageArguments(m));
         }
         catch (Exception e) {
         }
         return true;
       } } ;
   }
 
   private void layoutFields() {
     Background greyBg = BackgroundFactory.createSolidBackground(OandaMainScreen.BG_COLOR);
     setBackground(greyBg);
 
     Bitmap header = Bitmap.getBitmapResource("header-480x97.png");
     BitmapField headerBitmapField = new BitmapField(header);
     add(headerBitmapField);
 
     add(new SeparatorField());
 
     add(new SpacerField(300, 10));
 
     HorizontalFieldManager row1 = new HorizontalFieldManager(1152921504606846976L);
     this.helpHeaderTextLabel.setPadding(10, 30, 10, 30);
     row1.add(this.helpHeaderTextLabel);
     add(row1);
 
     add(new SpacerField(300, 10));
 
     HorizontalFieldManager row2 = new HorizontalFieldManager(1152921504606846976L);
 
     this.help2FASetupLabel.setPadding(0, 10, 5, 50);
     this.help2FASetupLabel.setFont(Font.getDefault());
     row2.add(this.help2FASetupLabel);
 
     add(row2);
 
     add(new SpacerField(300, 10));
 
     HorizontalFieldManager row3 = new HorizontalFieldManager(1152921504606846976L);
 
     this.helpMoreInfoLabel.setPadding(5, 10, 5, 50);
     this.helpMoreInfoLabel.setFont(Font.getDefault());
     row3.add(this.helpMoreInfoLabel);
 
     add(row3);
 
     add(new SpacerField(300, 10));
 
     HorizontalFieldManager row4 = new HorizontalFieldManager(1152921504606846976L);
 
     this.helpNeedToChangeLabel.setPadding(5, 10, 5, 50);
     this.helpNeedToChangeLabel.setFont(Font.getDefault());
     row4.add(this.helpNeedToChangeLabel);
 
     add(row4);
 
     add(new SpacerField(300, 10));
 
     HorizontalFieldManager row5 = new HorizontalFieldManager(1152921504606846976L);
 
     this.helpStillHavingTroubleLabel.setPadding(5, 10, 5, 50);
     this.helpStillHavingTroubleLabel.setFont(Font.getDefault());
     row5.add(this.helpStillHavingTroubleLabel);
 
     add(row5);
   }
 
   public boolean onClose() {
     this.controller.popScreen(this);
     return true;
   }
}

